#include <iostream>
using namespace std;

char* replace_blank(char* str) {
	int length = 0, blanks = 0;

	while (str[length] != '\0') {
		if (str[length] == ' ')
			blanks++;

		length++;
	}

	int newlength = length + 2*blanks;
	char* newbuff = (char*)malloc(newlength*sizeof(char) + 1);
	memset(newbuff, 0, newlength*sizeof(char) + 1);
	
	//int i = 0, j = 0;
	//while (str[i] != '\0') {
	//	if (str[i] == ' ') {
	//		newbuff[j++] = '%';
	//		newbuff[j++] = '2';
	//		newbuff[j++] = '0';
	//	}
	//	else
	//		newbuff[j++] = str[i];

	//	i++;
	//}

	int i = length-1, j = newlength-1;
	while (i>=0 && j>=0) {
		if (str[i] == ' ') {
			newbuff[j--] = '0';
			newbuff[j--] = '2';
			newbuff[j--] = '%';
		}
		else
			newbuff[j--] = str[i];

		i--;
	}

	return newbuff;
}

//int main() {
//	char* ptr  = replace_blank("  this is test ");
//	char* ptr2 = replace_blank("thisistest");
//	return 0;
//}